package com.teamone.etl.enterprise.entity;

import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.teamone.etl.exception.CommonCode;
import com.teamone.etl.exception.CustomException;
import com.teamone.etl.util.VerifyUtil;
import java.math.BigDecimal;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

/**
 (Enterprise)表实体类

 @author makejava
 @since 2021-01-19 16:31:58 */
@AllArgsConstructor
@NoArgsConstructor
public class Enterprise extends Model<Enterprise> {
    /**
     企业id
     */
    private Integer id;

    /**
     注册人-姓名
     */
    private String registrantPeopleName;

    /**
     注册人-手机号
     */
    private Long registrantMobileNumber;

    /**
     注册人职位
     */
    private String registrantPosition;

    /**
     注册日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date registrationDate;

    /**
     企业名称
     */
    private String enterpriseName;

    /**
     社会统一信用代码
     */
    private String socialUnifiedCreditCode;

    /**
     营业执照url
     */
    private String licenseImgUrl;

    /**
     状态 -1删除 0注册未审核 1注册已审核未认证 2待审核 3审核通过 4审核未通过
     */
    private Integer status;

    /**
     创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date createTime;

    /**
     修改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
    private Date updateTime;

    /**
     密码
     */
    private String password;

    /**
     公钥
     */
    private String accessKey;

    /**
     余额
     */
    private BigDecimal balance;

    /**
     已消费
     */
    private BigDecimal spent;

    /**
     地址
     */
    private String address;

    /**
     详细地址
     */
    private String detailedAddress;

    /**
     企业图片url
     */
    private String enterpriseImgUrl;

    public Integer getId () {
        return id;
    }

    public void setId (Integer id) {
        this.id = id;
    }

    public String getRegistrantPeopleName () {
        return registrantPeopleName;
    }

    public void setRegistrantPeopleName (String registrantPeopleName) {
        this.registrantPeopleName = registrantPeopleName;
    }

    public Long getRegistrantMobileNumber () {
        return registrantMobileNumber;
    }

    public void setRegistrantMobileNumber (Long registrantMobileNumber) {
        this.registrantMobileNumber = registrantMobileNumber;
    }

    public String getRegistrantPosition () {
        return registrantPosition;
    }

    public void setRegistrantPosition (String registrantPosition) {
        this.registrantPosition = registrantPosition;
    }

    public String getEnterpriseName () {
        return enterpriseName;
    }

    public void setEnterpriseName (String enterpriseName) {
        this.enterpriseName = enterpriseName;
    }

    public Date getRegistrationDate () {
        return registrationDate;
    }

    public void setRegistrationDate (Date registrationDate) {
        this.registrationDate = registrationDate;
    }

    public String getSocialUnifiedCreditCode () {
        return socialUnifiedCreditCode;
    }

    public void setSocialUnifiedCreditCode (String socialUnifiedCreditCode) {
        this.socialUnifiedCreditCode = socialUnifiedCreditCode;
    }

    public String getLicenseImgUrl () {
        return licenseImgUrl;
    }

    public void setLicenseImgUrl (String licenseImgUrl) {
        this.licenseImgUrl = licenseImgUrl;
    }

    public Integer getStatus () {
        return status;
    }

    public void setStatus (Integer status) {
        this.status = status;
    }

    public String getPassword () {
        return password;
    }

    public void setPassword (String password) {
        this.password = password;
    }

    public Date getCreateTime () {
        return createTime;
    }

    public void setCreateTime (Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime () {
        return updateTime;
    }

    public void setUpdateTime (Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getAccessKey () {
        return accessKey;
    }

    public void setAccessKey (String accessKey) {
        this.accessKey = accessKey;
    }

    public BigDecimal getBalance () {
        return balance;
    }

    public void setBalance (BigDecimal balance) {
        this.balance = balance;
    }

    public BigDecimal getSpent () {
        return spent;
    }

    public void setSpent (BigDecimal spent) {
        this.spent = spent;
    }

    public String getAddress () {
        return address;
    }

    public void setAddress (String address) {
        this.address = address;
    }

    public String getDetailedAddress () {
        return detailedAddress;
    }

    public void setDetailedAddress (String detailedAddress) {
        this.detailedAddress = detailedAddress;
    }

    public String getEnterpriseImgUrl () {
        return enterpriseImgUrl;
    }

    public void setEnterpriseImgUrl (String enterpriseImgUrl) {
        this.enterpriseImgUrl = enterpriseImgUrl;
    }

    public void verify1() throws CustomException {
        boolean flag = this.registrantMobileNumber != null && VerifyUtil.phone(this.registrantMobileNumber.toString());
        if(!flag){
            throw new CustomException(CommonCode.ENTERPRISE_MOBILE_INVALID);
        }

        flag = StringUtils.isEmpty(this.password);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_PASSWORD_INVALID);
        }
    }

    /**
     二次校验
     */
    public void verify2() throws CustomException {
        boolean flag = VerifyUtil.license(this.socialUnifiedCreditCode);
        if(!flag){
            throw new CustomException(CommonCode.ENTERPRISE_LICENSE_INVALID);
        }

        flag = StringUtils.isEmpty(this.registrantPeopleName);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_PEOPLE_INVALID);
        }

        flag = StringUtils.isEmpty(this.registrantPosition);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_POSITION_INVALID);
        }

        flag = this.registrationDate == null;
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_DATE_INVALID);
        }

        flag = StringUtils.isEmpty(this.enterpriseName);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_NAME_INVALID);
        }

        flag = StringUtils.isEmpty(this.licenseImgUrl);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_URL_INVALID);
        }

        flag = StringUtils.isEmpty(this.address);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_ADDRESS_INVALID);
        }

        flag = StringUtils.isEmpty(this.detailedAddress);
        if(flag){
            throw new CustomException(CommonCode.ENTERPRISE_DETAILED_ADDRESS_INVALID);
        }
    }

}